//设置高度
var height = window.innerHeight -83;
$('.bg').css('height',height)

var rightH =(height-60)/3;
var leftH =(height-168.5);
console.log(rightH);
$('#allorder').css('height',rightH)
$('#allmoney').css('height',rightH)
$('#alltime').css('height',rightH)
$('#map').css('height',leftH)

// 日期区间
var endtime= laydate.render({
    elem: '#end_time'
    
  });
  laydate.render({
    elem: '#start_time'
   ,done: function(value, date, endDate){
      console.log(value); //得到日期生成的值，如：2017-08-18
     
      console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
      console.log(endtime)
      date.month=(date.month-1)
       console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
      endtime.config.min=date
    }
  });
  
  Load()
  var data={};
  ajax(api.order.stat, data, 'post').done((res) => {
      Load(1)
      console.log(res)
      $('.order_money_total').text(res.data.order_money_total)
      $('.order_number_total').text(res.data.order_number_total)
      $('.order_time_total').text(res.data.order_time_total)
      //总订单数
      var allorder = echarts.init(document.getElementById('allorder'));
      option = {
        title: {
            text: "总订单数",
            x:'center',
            textStyle: {
                "color": "#83c7e3",
                "fontWeight": "bold",
            },
            top: "4%",    
        },
          tooltip: {
              trigger: 'item',
              formatter: "{a} <br/>{b} : {c} ({d}%)"
          },
          legend: {
              orient: 'vertical',
              left: '3%',
              top:'10%',
              textStyle:{color:"#fff"},
              data: ['行政执法', '特殊公务', '重要会议', '机要通讯', '视察调研', '公务接待', '应急公务', '紧急就医']
          },
          series: [{
              name: '订单数量',
              type: 'pie',
              radius: '55%',
              center: ['60%', '55%'],
              data: [{
                      value: res.data.order_number[1],
                      name: '行政执法'
                  },
                  {
                      value: res.data.order_number[2],
                      name: '特殊公务'
                  },
                  {
                      value: res.data.order_number[3],
                      name: '重要会议'
                  },
                  {
                      value: res.data.order_number[4],
                      name: '机要通讯'
                  },
                  {
                      value: res.data.order_number[5],
                      name: '视察调研'
                  },
                  {
                      value: res.data.order_number[6],
                      name: '公务接待'
                  },
                  {
                      value: res.data.order_number[7],
                      name: '应急公务'
                  },
                  {
                      value: res.data.order_number[8],
                      name: '紧急就医'
                  }
              ],
              itemStyle: {
                  emphasis: {
                      shadowBlur: 10,
                      shadowOffsetX: 0,
                      shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
              }
          }]
      };
      // 使用刚指定的配置项和数据显示图表。
      allorder.setOption(option);
  
      //总订单金额
              var allmoney = echarts.init(document.getElementById('allmoney'));
              option1 = {
                title: {
                    text: "总订单金额",
                    x:'center',
                    textStyle: {
                        "color": "#83c7e3",
                        "fontWeight": "bold",
                    },
                    top: "4%",    
                },
                  tooltip: {
                      trigger: 'item',
                      formatter: "{a} <br/>{b} : {c} ({d}%)"
                  },
                  legend: {
                      orient: 'vertical',
                      left: '3%',
                      top:'10%',
                      textStyle:{color:"#fff"},
                      data: ['行政执法', '特殊公务', '重要会议', '机要通讯', '视察调研', '公务接待', '应急公务', '紧急就医']
                  },
                  series: [{
                      name: '订单数量',
                      type: 'pie',
                      radius: '55%',
                      center: ['60%', '55%'],
                      data: [{
                              value: res.data.order_money[1],
                              name: '行政执法'
                          },
                          {
                              value: res.data.order_money[2],
                              name: '特殊公务'
                          },
                          {
                              value: res.data.order_money[3],
                              name: '重要会议'
                          },
                          {
                              value: res.data.order_money[4],
                              name: '机要通讯'
                          },
                          {
                              value: res.data.order_money[5],
                              name: '视察调研'
                          },
                          {
                              value: res.data.order_money[6],
                              name: '公务接待'
                          },
                          {
                              value: res.data.order_money[7],
                              name: '应急公务'
                          },
                          {
                              value: res.data.order_money[8],
                              name: '紧急就医'
                          }
                      ],
                      itemStyle: {
                          emphasis: {
                              shadowBlur: 10,
                              shadowOffsetX: 0,
                              shadowColor: 'rgba(0, 0, 0, 0.5)'
                          }
                      }
                  }]
              };
              allmoney.setOption(option1);
             
           
              var alltime = echarts.init(document.getElementById('alltime'));
              option2 = {
                title: {
                    text: "总耗时",
                    x:'center',
                    textStyle: {
                        "color": "#83c7e3",
                        "fontWeight": "bold",
                    },
                    top: "4%",    
                },
                  tooltip: {
                      trigger: 'item',
                      formatter: "{a} <br/>{b} : {c} ({d}%)"
                  },
                  legend: {
                      orient: 'vertical',
                      left: '3%',
                      top:'10%',
                      textStyle:{color:"#fff"},
                      data: ['行政执法', '特殊公务', '重要会议', '机要通讯', '视察调研', '公务接待', '应急公务', '紧急就医']
                  },
                  series: [{
                      name: '订单数量',
                      type: 'pie',
                      radius: '55%',
                      center: ['60%', '55%'],
                      data: [{
                              value: res.data.order_time[1],
                              name: '行政执法'
                          },
                          {
                              value: res.data.order_time[2],
                              name: '特殊公务'
                          },
                          {
                              value: res.data.order_time[3],
                              name: '重要会议'
                          },
                          {
                              value: res.data.order_time[4],
                              name: '机要通讯'
                          },
                          {
                              value: res.data.order_time[5],
                              name: '视察调研'
                          },
                          {
                              value: res.data.order_time[6],
                              name: '公务接待'
                          },
                          {
                              value: res.data.order_time[7],
                              name: '应急公务'
                          },
                          {
                              value: res.data.order_time[8],
                              name: '紧急就医'
                          }
                      ],
                      itemStyle: {
                          emphasis: {
                              shadowBlur: 10,
                              shadowOffsetX: 0,
                              shadowColor: 'rgba(0, 0, 0, 0.5)'
                          }
                      }
                  }]
              };
              alltime.setOption(option2);
          
  
      //总订单耗时	
  
  }).fail(() => {})
//地图
var map = echarts.init(document.getElementById('map'));
var uploadedDataURL = "{$static_dir}/assets/json/data-1517645039291-B1vgpymUz.json";

$.getJSON(uploadedDataURL, function(geoJson) {
    echarts.registerMap('zhongguo', geoJson);
    map.hideLoading();
    var geoCoordMap = {
        // "海南": [110.17, 19.92],
        "河南": [113.700339, 34.751827],
        "河北": [114.54095, 38.058913],
        "湖北": [114.289984, 30.5942],
        "广东": [113.293215, 23.102603],
        "湖南": [113.03042, 28.188898],
        "江西": [115.911671, 28.658012],
        "黑龙江": [126.629804, 45.774197],
        "四川": [104.112035, 30.630737],
        "安徽": [117.321109, 31.850184],
    }
    var data = [
        {
            name: '河南',
            value: 17737.01
        },
        {
            name: '河北',
            value: 13177.64
        },
        {
            name: '湖北',
            value: 12174.96
        },
        {
            name: '广东',
            value: 8230.15
        },
        {
            name: '湖南',
            value: 8173.05
        },
        {
            name: '江西',
            value: 74235.08
        },
        {
            name: '黑龙江',
            value: 6829.69
        },
        {
            name: '四川',
            value: 6158.43
        },
        {
            name: '安徽',
            value: 5930.80
        }
    ];
    var max = 100000,
        min = 900; // todo 
    var maxSize4Pin = 100,
        minSize4Pin = 20;

    var convertData = function(data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            }
        }
        return res;
    };

    console.log(convertData(data));

    var mapoption = {
       
        tooltip: {
            trigger: 'item',
            formatter: function(params) {
                if (typeof(params.value)[2] == "undefined") {
                    return params.name + ' : ' + params.value;
                } else {
                    return params.name + ' : ' + params.value[2];
                }
            }
        },
        legend: {
            orient: 'vertical',
            y: 'bottom',
            x: 'right',
            data: ['sell_area'],
            textStyle: {
                color: '#fff'
            }
        },
        visualMap: {
            show: false,
            min: 0,
            max: 500,
            left: 'left',
            top: 'bottom',
            text: ['高', '低'], // 文本，默认为数值文本
            calculable: true,
            seriesIndex: [1],
            inRange: {
                color: ['#0f0c29', '#302b63', '#24243e'] // 黑紫黑
            }
        },
  
        geo: {
            show: true,
            map: 'zhongguo',
            label: {
                normal: {
                    show: false
                },
                emphasis: {
                    show: false,
                }
            },
            roam: true,
            itemStyle: {
                normal: {
                    areaColor: '#031525',
                    borderColor: '#3B5077',
                },
                emphasis: {
                    areaColor: '#2B91B7',
                }
            }
        },
        series: [{
                name: 'credit_pm2.5',
                type: 'scatter',
                coordinateSystem: 'geo',
                data: convertData(data),
                symbolSize: function(val) {
                    return val[2] / 10000;
                },
                label: {
                    normal: {
                        formatter: '{b}',
                        position: 'right',
                        show: true
                    },
                    emphasis: {
                        show: true
                    }
                },
                itemStyle: {
                    normal: {
                        color: '#05C3F9'
                    }
                }
            },
            {
                type: 'map',
                map: 'zhongguo',
                geoIndex: 0,
                aspectScale: 0.75, //长宽比
                showLegendSymbol: false, // 存在legend时显示
                label: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false,
                        textStyle: {
                            color: '#fff'
                        }
                    }
                },
                roam: true,
                itemStyle: {
                    normal: {
                        areaColor: '#031525',
                        borderColor: '#3B5077',
                    },
                    emphasis: {
                        areaColor: '#2B91B7'
                    }
                },
                animation: false,
                data: data
            },
            {
                name: '点',
                type: 'scatter',
                coordinateSystem: 'geo',
                symbol: 'pin',
                symbolSize: function(val) {
                    var a = (maxSize4Pin - minSize4Pin) / (max - min);
                    var b = minSize4Pin - a * min;
                    b = maxSize4Pin - a * max;
                    return a * val[2] + b;
                },
                label: {
                    normal: {
                        show: true,
                        textStyle: {
                            color: '#fff',
                            fontSize: 9,
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: '#F62157', //标志颜色
                    }
                },
                zlevel: 6,
                data: convertData(data),
            },
            {
                name: 'Top 5',
                type: 'effectScatter',
                coordinateSystem: 'geo',
                data: convertData(data.sort(function(a, b) {
                    return b.value - a.value;
                }).slice(0, 5)),
                symbolSize: function(val) {
                    return val[2] / 5000;
                },
                showEffectOn: 'render',
                rippleEffect: {
                    brushType: 'stroke'
                },
                hoverAnimation: true,
                label: {
                    normal: {
                        formatter: '{b}',
                        position: 'right',
                        show: false
                    }
                },
                itemStyle: {
                    normal: {
                        color: '#05C3F9',
                        shadowBlur: 10,
                        shadowColor: '#05C3F9'
                    }
                },
                zlevel: 1
            },

        ]
    };
    map.setOption(mapoption);
});
  
  